package com.king.first.app.watermark;

import com.king.first.bean.Event;
import org.apache.flink.streaming.api.functions.source.SourceFunction;

import java.util.Random;

/**
 * @author wdl
 * @date 2022/4/16 11:37
 */
public class ClickSource implements SourceFunction<Event> {
    @Override
    public void run(SourceContext<Event> ctx) throws Exception {

        String[] users = {"aaa", "bbb", "ccc"};
        String[] url = {"/user", "/list", "/menu"};

        Random random = new Random();
        while (true) {
            Thread.sleep(500);
            int index = random.nextInt(3);
            Event event = new Event();
            event.setUser(users[index]);
            event.setTimestamp(System.currentTimeMillis());
            event.setUrl(url[index]);
            ctx.collect(event);
        }
    }

    @Override
    public void cancel() {

    }
}
